﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevTeam;
using System;
using System.Data;

namespace ConfExpert.Forms.Espresso
{
    public partial class PerfArt : XForm
    {
        public PerfArt()
        {
            InitializeComponent();
        }

        private void PerfArt_Load(object sender, EventArgs e)
        {
            DataSet d = ExecuteDataSet("GetPerfArt");

            Hazirla(gridView1, d.Tables[0]);
            Hazirla(gridView2, d.Tables[1]);
            Hazirla(gridView3, d.Tables[2]);
            Hazirla(gridView4, d.Tables[3]);
        }

        private void Hazirla(GridView gv, DataTable t)
        {
            gv.Init(t);
            foreach (GridColumn col in gridView1.Columns)
                if (col.ColumnType == typeof(decimal))
                {
                    gv.FormatAsNumber(1, col.FieldName);
                    gv.AddSummary(col.FieldName);

                    GridFormatRule gridFormatRuleY = new GridFormatRule();
                    FormatConditionRuleDataBar formatConditionRuleDataBarY = new FormatConditionRuleDataBar();
                    gridFormatRuleY.Column = gv.Columns[col.FieldName];
                    formatConditionRuleDataBarY.PredefinedName = (col.FieldName == "9999" ? "Yellow Gradient" : "Green Gradient");
                    gridFormatRuleY.Rule = formatConditionRuleDataBarY;
                    gv.FormatRules.Add(gridFormatRuleY);
                }
            gv.SetCaptions("9999:Genel Toplam");
            gv.BestFitColumns();
        }
    }
}
